package utils
{
import core.StageProxy;

import flash.display.StageDisplayState;
import flash.external.ExternalInterface;

public class JavascriptAPI
{
	private static var invoker:Object = {};
	
	public static function call(name:String, ...args):void
	{
		if (JS_ENABLED)
		{
            StageProxy.changeScreenMode(StageDisplayState.NORMAL);
            
			var params:Array = [ name ];
			params = params.concat(args);
			ExternalInterface.call.apply(invoker, params);
		}
	}
	
	public static function addCallback(name:String, callBack:Function):void
	{
		if (JS_ENABLED)
		{
			ExternalInterface.addCallback(name, callBack);
		}
	}
	
	public static function get JS_ENABLED():Boolean
	{
		return ExternalInterface.available;
	}
}
}